<%
sel_task_id = session[:selected_task].to_i
children = @tasks.select {|t| t.task_id==sel_task_id}
%>

<%= pluralize(children.size, "task")%><br/>

<div class="button_bar">
<%= link_to_function('new task', 'add_new_row()', {:onmouseover=>"mover('a')", :onmouseout=>"mover('')", :class=>'button' }) %>
<%= link_to('review', '/inbox/review', {:onmouseover=>"mover('review')", :onmouseout=>"mover('')", :class=>'btnlnk' }) %>
<%= link_to_function('deadlines','$("deadlines").toggle();$("taskslist").toggle()', {:class=>'btnlnk'}) %>
<img id="loading" src="/images/loading.gif" style="display:none;">
</div>

<a href="#" title="display root tasks" onclick="$('loading').show();disp_sub(0);return false;"><img src="/images/sitemap-green.gif"></a>

<%
if(sel_task_id != 0)
  sel_task = Task.find(sel_task_id)
-%>
  <a href="#" title="go up" onclick="$('disp_up').src='/images/loading.gif';disp_sub(<%=sel_task.task_id%>);return false;"><img id="disp_up" src="/images/disp_up.gif"></a>
  <%= render(:partial => "task_title", :object => sel_task) %>
<% end -%>

<% form_tag({:action=> :post}, {:name => 'tasksform'}) do %>

<!-- Tasks -->

<div id='deadlines' style="display:none;" class="groupbox">
<div id="title">Deadlines</div>
<div id='deadlines_content'>
<%= render(:partial=>'task/deadline_tasks', :locals=>{:deadlines=>@deadlines, :tasks=>@tasks}) %>
</div>
</div>

<% if @tasks.size == 0 -%>
No tasks. To add a task, click 'New Task'<br/>
<br/>
<% end -%>


<ul id="taskslist" class="sortablelist">
<% 
by_tag = nil if (defined? by_tag) == nil # default value, so we don't have to pass it every time as :locals
if(by_tag!=nil) %>
<%= render(:partial => "task", :collection => @tasks, :locals=>{:tasks=>@tasks, :item_name=>'item'}) %>
<% else %>
<% # render(:partial => "by_state", :locals=>{:tasks=>children}) %>
<%= render(:partial => "task", :collection => children, :locals=>{:tasks=>@tasks, :item_name=>'item'}) %>
<% end %>
</ul>
<br/>
<br/>

<!-- Tasks done -->

<%= link_to_remote("Display done tasks",
   {:update => :tasksdone,
    :url =>{ :action => :display_tasks_done },
    :loading=>visual_effect('appear', 'loading2'),
    :success=>visual_effect('fade', 'loading2')},
   {:class=>'btnlnk', :id=>'done_link'})
%>
<img id="loading2" src="/images/loading.gif" style="display:none;">
<div id="tasksdone">
	<ul id="taskdoneul" class="mylist"></ul>
</div>
<% end %>

<%= sortable_element('taskslist', {:url => { :action => "order" }}) %>

